﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using MINERP.COM;
using System.Data.Common;

namespace MINERP.DAL.CustomerManage
{
    public class UserDAL : DALBase
    {
        public static users GetUserByID(int userid)
        {
            ObjectQuery<users> objs = DataEntites.users.Where(string.Format("it.userID = {0}", userid));

            foreach (users record in objs)
            {
                return record;
            }

            return null;
        }

        /// <summary>
        /// 得到所有的用户
        /// </summary>
        /// <returns></returns>
        public static List<UserInfo> GetUserInfo()
        {
            List<UserInfo> collection = new List<UserInfo>();

            ObjectQuery<DbDataRecord> objs = DataEntites.CreateQuery<DbDataRecord>("SELECT it.userID, it.UserName FROM users as it");

            UserInfo hold = new UserInfo();
            hold.UserID = -1;
            hold.UserName = string.Empty;
            collection.Add(hold);

            foreach (var item in objs)
            {
                UserInfo obj = new UserInfo();

                obj.UserID = (int)item["userID"];
                obj.UserName = item["UserName"].ToString();

                collection.Add(obj);
            }

            return collection;
        }
        /// <summary>
        /// 根据orderId获取Order
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public static Tb_OrderBag GetOrderByOrderId(int orderId)
        {
            try
            {
                Tb_OrderBag order = DataEntites.Tb_OrderBag.Where(p => p.OrderBagId == orderId).FirstOrDefault();
                return order;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
